﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WWX.Admin.Web.Common
{
    public static class JsonResultHelper
    {
        public static JsonResult CreateRichJsonResult(bool isSuccess = true, string message = "", object data = null)
        {
            var result = new JsonResult();
            result.Data = JsonObject(isSuccess, message, data);
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }

        public static JsonResult CreateJsonResult(object data)
        {
            return new JsonResult() { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        public static JsonResult CreateJqueryDataTableJsonResult(int draw, int totalCount, object rows)
        {
            var data = new { draw = draw, recordsTotal = totalCount, recordsFiltered = totalCount, data = rows };
            return new JsonResult() { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        private static object JsonObject(bool success = true, string message = "", object data = null)
        {
            return new { success = success, message = message, data = data };
        }
    }
}